package com.link2room.quintesson.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.quintesson.dto.param.manager.TaobaoHotelRateplanManagerParamDto;
import com.link2room.quintesson.dto.param.base.TaobaoXrateplanHotelBaseParamDto;
import com.link2room.quintesson.dto.result.base.TaobaoXrateplanHotelDto;
import com.link2room.quintesson.facade.ITaobaoHotelRateplanFacadeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by VegetaKo on 2017/1/12.
 */
@RestController
@RequestMapping("/manager/TaobaoXrateplanHotels")
public class TaobaoXrateplanHotelManagerController {

    @Resource
    private ITaobaoHotelRateplanFacadeService taobaoHotelRateplanFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto taobaoXrateplanList(
            @RequestParam(value = "rpCode" ,required = false) String rpCode,
            @RequestParam(value = "currentPage" ,required = false) Integer currentPage,
            @RequestParam(value = "pageSize" ,required = false) Integer pageSize
    ) throws Exception {
        TaobaoXrateplanHotelBaseParamDto taobaoXrateplanHotelBaseParamDto=new TaobaoXrateplanHotelBaseParamDto();
        taobaoXrateplanHotelBaseParamDto.setRpCode(rpCode);
        taobaoXrateplanHotelBaseParamDto.setCurrentPage(currentPage);
        taobaoXrateplanHotelBaseParamDto.setPageSize(pageSize);
        QueryResult<TaobaoXrateplanHotelDto> taobaoXrateplanHotelResult = taobaoHotelRateplanFacadeService.listTaobaoXrateplanHotels(taobaoXrateplanHotelBaseParamDto);
        BaseResultDto<TaobaoXrateplanHotelDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(taobaoXrateplanHotelResult);
        return baseResultDto;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public BaseResultDto taobaoXrateplan(
            @PathVariable Long id
    ) throws Exception {
        TaobaoXrateplanHotelBaseParamDto taobaoXrateplanHotelBaseParamDto=new TaobaoXrateplanHotelBaseParamDto();
        taobaoXrateplanHotelBaseParamDto.setId(id);
        TaobaoXrateplanHotelDto taobaoXrateplanDto = taobaoHotelRateplanFacadeService.findTaobaoXrateplanHotelById(taobaoXrateplanHotelBaseParamDto);
        BaseResultDto<TaobaoXrateplanHotelDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(taobaoXrateplanDto);
        return baseResultDto;
    }

    @RequestMapping(method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXrateplanHotelList(
            @RequestBody TaobaoHotelRateplanManagerParamDto taobaoHotelRateplanManagerParamDto
    )throws Exception{
        QueryResult<TaobaoXrateplanHotelDto> taobaoXrateplanHotelDtoQueryResult = taobaoHotelRateplanFacadeService.updateTaobaoHotelRateplanList(taobaoHotelRateplanManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(taobaoXrateplanHotelDtoQueryResult);
        return l2rRs;
    }

    @RequestMapping(value = "/TaobaoXrateplanHotel",method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXrateplanHotel(
            @RequestBody TaobaoXrateplanHotelBaseParamDto taobaoXrateplanHotelBaseParamDto
    )throws Exception{
        TaobaoXrateplanHotelDto taobaoXrateplanHotelDto=taobaoHotelRateplanFacadeService.saveOrUpdateTaobaoXrateplanHotel(taobaoXrateplanHotelBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(taobaoXrateplanHotelDto);
        return l2rRs;
    }
}
